<template>
  <div class="maintenancePlan">
    <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
  </div>
</template>
<script>
import { queryExperimrntPlanList } from "@/api/productionPlan/maintenancePlan.js";
export default {
  data() {
    return {
      pageType: "list",
      tableSetting: {
        pageConfig: {
          pageCode: "experimentPlan",
          userId: this.$store.getters.userInfo.namePy,
        },
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "text",
              label: "计划名称",
              model: "name",
            },
            {
              type: "select",
              label: "专业",
              model: "major",
              option: this.$store.getters.dirtData("common_major"),
            },
            {
              type: "organization",
              label: "创建单位",
              model: "deptName",
              idsStr: "deptId",
            },
            {
              type: "select",
              label: "状态",
              model: "status",
              placeholder: "请输入",
              option: this.$store.getters.dirtData("plan_experiment_status"),
            },
            {
              type: "input",
              label: "计划编号",
              model: "code",
            },
            {
              type: "userOnly",
              label: "创建人",
              model: "createByName",
              idsStr: "createBy",
            },
            {
              type: "daterange",
              label: "创建时间",
              model: "createTime",
            },
            {
              type: "select",
              label: "定时下发",
              model: "isTimer",
              placeholder: "请输入",
              option: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
          ],
        },
        //过滤器的值
        filterFormData: {},
        //过滤器的默认值
        defaultFilterData: {},
        userCustomData: [],
        actionList: [
          {
            name: "新建",
            icon: "el-icon-plus",
            disabled: !this.$store.getters.isBtnAuth("add"), //控制按钮的禁用
            content: "未授权功能", //禁用提示内容
            method: (row) => {
              this.goDetailPage(row, "experimentPlanOnlyDetail", "add");
            },
          },
        ],
        column: [
          {
            label: "编号",
            prop: "code",
            sortable: "custom"
          },
          {
            label: "计划名称",
            prop: "name",
            sortable: "custom"
          },
          {
            label: "专业",
            prop: "major",
            sortable: "custom",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "common_major",
                row.major
              );
            },
          },
          {
            label: "状态",
            prop: "status",
            sortable: "custom",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "plan_experiment_status",
                row.status
              );
            },
          },
          {
            label: "定时下发",
            prop: "isTimer",
            sortable: "custom",
            formatter: (row) => {
              return row.isTimer == 1 ? "是" : "否";
            },
          },
          {
            label: "当前节点",
            prop: "currentNode",
            sortable: "custom"
          },
          {
            label: "当前处理人",
            prop: "currentNodeUserName",
            showTooltip: true,
            sortable: "custom"
          },
          {
            label: "创建单位",
            prop: "deptName",
            sortable: "custom"
          },
          {
            label: "创建人",
            prop: "createByName",
            sortable: "custom"
          },
          {
            label: "创建时间",
            prop: "createTime",
            sortable: "custom"
          },
        ],
        paginationObj: {
          pageSizes: [15, 30, 50, 100],
        },
        totalNumber: 0,
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {
            this.goDetailPage(row, "experimentPlanOnlyDetail", "edit");
          },
        },
      },
    };
  },
  created() {
    /* 添加监听事件 */
    window.addEventListener("storage", this.updateData);
  },
  beforeDestroy() {
    /* 删除监听事件 */
    window.removeEventListener("storage", this.updateData);
  },
  mounted() {
    this.$refs.klTable.getTableConfig();
    //this.updateData();
  },
  methods: {
    updateData() {
      this.$refs.klTable.searchData();
    },
    // 获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryExperimrntPlanList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    },
    //跳转到详情页
    goDetailPage(row, router, type) {
      const { href } = this.$router.resolve({
        name: router,
        query: {
          id: row ? row.id : "",
          // pageType: type ? type : "",
        },
      });
      window.open(href, "_blank");
    },
  },
};
</script>
<style lang="less" scoped>
.maintenancePlan{
  height:calc(100% - 10px);
}
</style>